use flate2::read::{GzDecoder, GzEncoder};
use flate2::Compression;
use std::fs::File;
use tar::Archive;

// 压缩tar.gz
#[test]
fn demo01() -> Result<(), std::io::Error> {
    let base_path = "c:/Users/he_pe/Desktop/";
    let tar_gz = File::create(base_path.to_owned() + "archive.tar.gz")?;
    let enc = GzEncoder::new(tar_gz, Compression::default());
    let mut tar = tar::Builder::new(enc);
    tar.append_dir_all("", base_path.to_owned() + "demo-compress")?;
    tar.finish()?;
    Ok(())
}

// 解压tar.gz
// Error: Custom { kind: InvalidInput, error: TarError { desc: "failed to iterate over archive", io: Custom { kind: InvalidInput, error: "invalid gzip header" } } }
#[test]
fn demo02() -> Result<(), std::io::Error> {
    let base_path = "c:/Users/he_pe/Desktop/";
    let tar_gz = File::open(base_path.to_owned() + "archive.tar.gz")?;
    let tar = GzDecoder::new(tar_gz);
    let mut archive = Archive::new(tar);
    archive.unpack(base_path.to_owned() + "uncompressed/")?;
    Ok(())
}



fn main() {}
